//
//  ViewController.m
//  testWebView
//
//  Created by DIANGHONG on 2018/5/24.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "ViewController.h"
#import <WebKit/WebKit.h>
@interface ViewController ()<WKNavigationDelegate>
@property(nonatomic ,strong)WKWebView *webView;
@property(nonatomic ,strong)NSString *url;
@property(nonatomic ,strong)NSString *currentUrl;
@end

@implementation ViewController

- (void)setCurrentUrl:(NSString *)currentUrl
{
    _currentUrl = currentUrl;
   // NSString *url = [NSString stringWithFormat:@"%@&%@",currentUrl,@"comefrom=app"];
    //[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.url = @"http://jpjd.cnaite.cn/wap/";
    WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
    self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:config];
    self.webView.navigationDelegate = self;
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
    [self.view addSubview:self.webView];
}

//WKNavigationDelegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    NSString *strRequest = [navigationAction.request.URL.absoluteString stringByRemovingPercentEncoding];
    
    if([strRequest isEqualToString:self.url]) {//主页面加载内容
        
        decisionHandler(WKNavigationActionPolicyAllow);//允许跳转
        
    } else {//截获页面里面的链接点击
      //  self.currentUrl = navigationAction.request.URL.absoluteString;
        //navigationAction.request.URL
        
        
        decisionHandler(WKNavigationActionPolicyAllow);//不允许跳转
        
    }
}


@end
